package com.bootdo.blog.dao;

import com.bootdo.blog.domain.PesticideDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface PesticideMapper {

	@Select("select `pest_id`, `batch`, `supplier`, `title`, `count`, `size`, `origin`, `license_number`, `date_pro`, `shelf_life`, `telephone`, `organ_code`, `organ_name`, `surveyor` from tb_pesticide where pest_id = #{id}")
	PesticideDO get(Integer pestId);
	
	@Select("<script>" +
	"select * from tb_pesticide " + 
			"<where>" + 
		  		  "<if test=\"pestId != null and pestId != ''\">"+ "and pest_id = #{pestId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"supplier != null and supplier != ''\">"+ "and supplier = #{supplier} " + "</if>" + 
		  		  "<if test=\"title != null and title != ''\">"+ "and title = #{title} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"size != null and size != ''\">"+ "and size = #{size} " + "</if>" + 
		  		  "<if test=\"origin != null and origin != ''\">"+ "and origin = #{origin} " + "</if>" + 
		  		  "<if test=\"licenseNumber != null and licenseNumber != ''\">"+ "and license_number = #{licenseNumber} " + "</if>" + 
		  		  "<if test=\"datePro != null and datePro != ''\">"+ "and date_pro = #{datePro} " + "</if>" + 
		  		  "<if test=\"shelfLife != null and shelfLife != ''\">"+ "and shelf_life = #{shelfLife} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"organCode != null and organCode != ''\">"+ "and organ_code = #{organCode} " + "</if>" + 
		  		  "<if test=\"organName != null and organName != ''\">"+ "and organ_name = #{organName} " + "</if>" + 
		  		  "<if test=\"surveyor != null and surveyor != ''\">"+ "and surveyor = #{surveyor} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by pest_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<PesticideDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_pesticide " + 
			"<where>" + 
		  		  "<if test=\"pestId != null and pestId != ''\">"+ "and pest_id = #{pestId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"supplier != null and supplier != ''\">"+ "and supplier = #{supplier} " + "</if>" + 
		  		  "<if test=\"title != null and title != ''\">"+ "and title = #{title} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"size != null and size != ''\">"+ "and size = #{size} " + "</if>" + 
		  		  "<if test=\"origin != null and origin != ''\">"+ "and origin = #{origin} " + "</if>" + 
		  		  "<if test=\"licenseNumber != null and licenseNumber != ''\">"+ "and license_number = #{licenseNumber} " + "</if>" + 
		  		  "<if test=\"datePro != null and datePro != ''\">"+ "and date_pro = #{datePro} " + "</if>" + 
		  		  "<if test=\"shelfLife != null and shelfLife != ''\">"+ "and shelf_life = #{shelfLife} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"organCode != null and organCode != ''\">"+ "and organ_code = #{organCode} " + "</if>" + 
		  		  "<if test=\"organName != null and organName != ''\">"+ "and organ_name = #{organName} " + "</if>" + 
		  		  "<if test=\"surveyor != null and surveyor != ''\">"+ "and surveyor = #{surveyor} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_pesticide (`batch`, `supplier`, `title`, `count`, `size`, `origin`, `license_number`, `date_pro`, `shelf_life`, `telephone`, `organ_code`, `organ_name`, `surveyor`)"
	+ "values (#{batch}, #{supplier}, #{title}, #{count}, #{size}, #{origin}, #{licenseNumber}, #{datePro}, #{shelfLife}, #{telephone}, #{organCode}, #{organName}, #{surveyor})")
	int save(PesticideDO pesticide);
	
	@Update("<script>"+ 
			"update tb_pesticide " + 
					"<set>" + 
		            "<if test=\"pestId != null\">`pest_id` = #{pestId}, </if>" + 
                    "<if test=\"batch != null\">`batch` = #{batch}, </if>" + 
                    "<if test=\"supplier != null\">`supplier` = #{supplier}, </if>" + 
                    "<if test=\"title != null\">`title` = #{title}, </if>" + 
                    "<if test=\"count != null\">`count` = #{count}, </if>" + 
                    "<if test=\"size != null\">`size` = #{size}, </if>" + 
                    "<if test=\"origin != null\">`origin` = #{origin}, </if>" + 
                    "<if test=\"licenseNumber != null\">`license_number` = #{licenseNumber}, </if>" + 
                    "<if test=\"datePro != null\">`date_pro` = #{datePro}, </if>" + 
                    "<if test=\"shelfLife != null\">`shelf_life` = #{shelfLife}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
                    "<if test=\"organCode != null\">`organ_code` = #{organCode}, </if>" + 
                    "<if test=\"organName != null\">`organ_name` = #{organName}, </if>" + 
                    "<if test=\"surveyor != null\">`surveyor` = #{surveyor}, </if>" + 
          					"</set>" + 
					"where pest_id = #{pestId}"+
			"</script>")
	int update(PesticideDO pesticide);
	
	@Delete("delete from tb_pesticide where pest_id =#{pestId}")
	int remove(Integer pest_id);
	
	@Delete("<script>"+ 
			"delete from tb_pesticide where pest_id in " + 
					"<foreach item=\"pestId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{pestId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] pestIds);
}
